/*
 *
 * Copyright(c) 2010 Safelayer Secure Communications
 *
 * This is open source software, placed under the terms of the
 * GNU GENERAL PUBLIC LICENSE Version 3.
 * Please see: http://www.gnu.org/licenses/gpl-3.0.txt
 * 
 * Permission to use, copy, modify, and distribute this software
 * for any purpose and without fee is hereby granted, provided
 * that the above copyright notices appear in all copies and that
 * both the copyright notice and this permission notice appear in
 * supporting documentation.
 * 
 */
package com.neuralnoise.foaf.core;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * Models a FOAF Image. The class <code>Image</code> is a sub-class of {@link Document}
 * corresponding to those documents which are images.
 * <p>
 * 
 * For more info see FOAF Vocabulary Specification
 * 
 * @author victor.martinez <swtp@safelayer.com>
 */
public class Image extends Document {

	private Set<Image> thumbnailSet = new LinkedHashSet<Image>();

	private Set<Thing> depictsSet = new LinkedHashSet<Thing>();

	public Image() {
		super(null);
	}

	public Image(String uri) {
		super(uri);
	}

	/**
	 * Returns all thumbnails.
	 * 
	 * @return Returns all thumbnails.
	 */
	public List<Image> getAllThumbnails() {
		return new ArrayList<Image>(thumbnailSet);
	}

	/**
	 * Adds the specified <code>thumbnail</code> to this {@link Image} if it is not already present.
	 * 
	 * @param thumbnail The <code>thumbnail</code> to be added to this <code>Image</code> .
	 * @return <tt>true</tt> if the <code>Image</code>. did not already contain the specified
	 *         <code>thumbnail</code>
	 */
	public boolean addThumbnail(Image thumbnail) {
		return thumbnailSet.add(thumbnail);
	}

	/**
	 * Removes the specified <code>thumbnail</code> from this {@link Image}, if it is present. Returns
	 * <tt>true</tt> if this <code>Image</code> contained the specified <code>thumbnail</code> (or
	 * equivalently, if this <code>Image</code> changed as a result of the call).
	 * 
	 * @param thumbnail The <code>thumbnail</code> to be removed from this <code>Image</code>.
	 * @return <tt>true</tt> if this <code>Image</code> contained the specified
	 *         <code>thumbnail</code>.
	 */
	public boolean removeThumbnail(Image thumbnail) {
		return thumbnailSet.remove(thumbnail);
	}

	/**
	 * Removes all of the thumbnails from this {@link Image}. The thumbnails from <code>Image</code>
	 * will be empty after this call returns.
	 */
	public void clearThumbnails() {
		thumbnailSet.clear();
	}

	/**
	 * Returns <tt>true</tt> if this {@link Image} contains the specified <code>thumbnail</code>
	 * 
	 * @param thumbnail The <code>thumbnail</code> whose presence in this <code>Image</code> is to
	 *            be tested.
	 * @return <tt>true</tt> if this <code>Image</code> contains the specified
	 *         <code>thumbnail</code>.
	 */
	public boolean containsThumbnail(Image thumbnail) {
		return thumbnailSet.contains(thumbnail);
	}

	/**
	 * Returns all depicts.
	 * 
	 * @return Returns all depicts.
	 */
	public List<Thing> getAllDepictss() {
		return new ArrayList<Thing>(depictsSet);
	}

	/**
	 * Adds the specified <code>depicts</code> to this {@link Image} if it is not already present.
	 * 
	 * @param depicts The <code>depicts</code> to be added to this <code>Image</code> .
	 * @return <tt>true</tt> if the <code>Image</code>. did not already contain the specified
	 *         <code>depicts</code>.
	 */
	public boolean addDepicts(Thing depicts) {
		return depictsSet.add(depicts);
	}

	/**
	 * Removes the specified <code>depicts</code> from this {@link Image}, if it is present. Returns
	 * <tt>true</tt> if this <code>Image</code> contained the specified <code>depicts</code> (or
	 * equivalently, if this <code>Image</code> changed as a result of the call).
	 * 
	 * @param depicts The <code>depicts</code> to be removed from this <code>Image</code>.
	 * @return <tt>true</tt> if this <code>Image</code> contained the specified <code>depicts</code>
	 */
	public boolean removeDepicts(Thing depicts) {
		return depictsSet.remove(depicts);
	}

	/**
	 * Removes all of the depicts from this {@link Image}. The depicts from <code>Image</code> will
	 * be empty after this call returns.
	 */
	public void clearDepicts() {
		depictsSet.clear();
	}

	/**
	 * Returns <tt>true</tt> if this {@link Image} contains the specified <code>depicts</code>
	 * 
	 * @param depicts The <code>depicts</code> whose presence in this <code>Image</code> is to be
	 *            tested.
	 * @return <tt>true</tt> if this <code>Image</code> contains the specified <code>depicts</code>
	 */
	public boolean containsDepicts(Thing depicts) {
		return depictsSet.contains(depicts);
	}
}
